package top.jiangqiang.qianyi.web.controller.admin;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.jiangqiang.qianyi.business.model.request.SysLogListRequest;
import top.jiangqiang.qianyi.business.model.request.SysLogPageRequest;
import top.jiangqiang.qianyi.business.model.response.SysLogDetailResponse;
import top.jiangqiang.qianyi.business.model.response.SysLogListResponse;
import top.jiangqiang.qianyi.business.model.response.SysLogPageResponse;
import top.jiangqiang.qianyi.business.service.SysLogService;
import top.jiangqiang.qianyi.common.base.controller.BaseController;
import top.jiangqiang.qianyi.common.base.model.response.PageResult;
import top.jiangqiang.qianyi.common.base.model.response.Result;
import top.jiangqiang.qianyi.common.constants.GlobalConstants;
import top.jiangqiang.qianyi.common.constants.log.SysLogType;
import top.jiangqiang.qianyi.common.log.annotations.Log;

import java.util.List;

/**
 * <p>
 * 系统日志 前端控制器
 * </p>
 *
 * @author JiangQiang
 * @since 2024-06-03
 */
@Tag(name = "系统日志接口", description = "")
@RestController
@RequiredArgsConstructor
@RequestMapping(GlobalConstants.AdminRequestURLConstants.ADMIN_CONTROLLER_PREFIX + "/sysLog")
public class AdminSysLogController extends BaseController {
    private final SysLogService sysLogService;

    @GetMapping("/page")
    @Operation(summary = "系统日志分页查询")
    @Log(value = "系统日志分页查询", type = SysLogType.PAGE)
    public Result<PageResult<SysLogPageResponse>> page(@Validated @ParameterObject SysLogPageRequest request) {
        return sysLogService.page(request);
    }

    @GetMapping("/list")
    @Operation(summary = "系统日志全表查询")
    @Log(value = "系统日志全表查询", type = SysLogType.LIST)
    public Result<List<SysLogListResponse>> list(@Validated @ParameterObject SysLogListRequest request) {
        return sysLogService.list(request);
    }

    @GetMapping("/{id}")
    @Operation(summary = "系统日志详情")
    @Log(value = "系统日志详情", type = SysLogType.DETAIL)
    public Result<SysLogDetailResponse> detail(@NotNull(message = "ID不能为空") @PathVariable("id") Long id) {
        return sysLogService.detail(id);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "系统日志删除")
    @Log(value = "系统日志删除", type = SysLogType.DELETE)
    public Result<Void> delete(@NotNull(message = "ID不能为空") @PathVariable("id") Long id) {
        return sysLogService.delete(id);
    }

}
